package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

	@FindBy(xpath ="//a[@href='http://localhost/php4dvd/?logout']")
	public WebElement menuLogOutLink;
	
	@FindBy(xpath ="//a[@href='http://localhost/php4dvd/?go=profile']")
	public WebElement menuMyProfileLink;
	
	@FindBy(xpath ="//a[@href='http://localhost/php4dvd/?go=users']")
	public WebElement menuUserManagementLink;
	
	@FindBy(xpath ="//a[@href='http://localhost/php4dvd/']")
	public WebElement menuHomeLink;
	
	public boolean isOnLogOutLink() {
		return menuLogOutLink.isDisplayed();
	}
	
	public boolean isOnThisPage() {
		return menuLogOutLink.isDisplayed();
	}
	
	public LoginPage logout() {
		menuLogOutLink.click();
		driver.switchTo().alert().accept();
		return MyPageFactory.getPage(driver, LoginPage.class);
	}
	
	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin","admin");
	}
	
	public UserManagementPage gotoUserManagementConsole() {
		menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, UserManagementPage.class);
	}
	
	public HomePage gotoHomePage() {
		menuHomeLink.click();
		return MyPageFactory.getPage(driver, HomePage.class);
	}
	
	public MyProfilePage gotoMyProfilePage() {
		menuMyProfileLink.click();
		return MyPageFactory.getPage(driver, MyProfilePage.class);
	}
	
	
}
